from scikits.audiolab import wavwrite
#Sampling Frequency:
Fs = 48000
#Create 1 second long vector of zeros:
pulse = np.zeros(Fs)
#Starting and ending points of pulse:
start = 12000
end = 24000
#Create pulse with amplitude of 0.9:
pulse[start:end] = 0.9*np.ones(end-start)
#plot pulse
plot(pulse, linewidth=2)
grid(1)
ylim([-1,1])
xlabel('Samples')
ylabel('Voltage')
<matplotlib.text.Text at 0x106744850>
#Write pulse to wave file in sounds directory:
wavwrite(pulse, 'sounds/pulse.wav', Fs)
#Play in iPython Notebook:
from IPython.display import Audio
Audio('sounds/pulse.wav')
from scikits.audiolab import wavread
#Import recorded pulse:
recordedPulse, Fs, enc = wavread('sounds/recordedPulse.wav')
#Create zero-padded version to line up with input pulse:
zeroPaddedSignal = np.zeros(Fs)
zeroPaddedSignal[start:start+recordedPulse.shape[0]] = \
recordedPulse[:,0]
#Plot both Signals:
fig = figure(0, (12,8))
subplot(2,1,1)
plot(pulse, 'b', linewidth = 2)
grid(1)
ylim([-1, 1])
ylabel('Voltage')
xlabel('Samples')
title('Input Pulse')
subplot(2,1,2)
plot(zeroPaddedSignal, 'r', linewidth=2)
grid(1)
ylim([-1,1])
xlabel('Samples')
title('Recorded Pulse')
<matplotlib.text.Text at 0x10666fa10>
#Plot both Signals:
fig = figure(0, (12,6))
plot(pulse, 'b', linewidth = 2)
grid(1)
ylim([-1, 1])
ylabel('Voltage')
<matplotlib.text.Text at 0x10672e590>
#Plot both Signals:
fig = figure(0, (12,6))
plot(zeroPaddedSignal, 'r', linewidth=2)
grid(1)
ylim([-1, 1])
ylabel('Voltage')
xlabel('Samples')
<matplotlib.text.Text at 0x10671bed0>